#include <myheader_c_plus.h>
using std::string;
using std::endl;
using std::cout;
using std::unique_ptr;

class Figure
{
public:
    virtual void display() = 0;
    virtual double getArea() = 0;
    virtual ~Figure(){}

};
class Circle
:public Figure
{
public:
    Circle()
    :_r(1)
    {

    }
    Circle(int r)
        :_r(r)
    {

    }

    void display()
    {
        cout << "Circle" << endl; 
    }

    double getArea()
    {
        return 3.14 * _r * _r;
    }


private:
    int _r;
};
class Traingle
:public Figure
{
public:
    Traingle()
    :_a(1)
    ,_b(1)
    ,_c(1)
    {

    }
    Traingle(int a, int b, int c)
        :_a(a)
         ,_b(b)
         ,_c(c)
    {

    }

    void display()
    {
        cout << "Tranigle" << endl; 
    }

    double getArea()
    {
        // 计算半周长
        double s = (_a + _b + _c) / 2;

        // 使用海伦公式计算面积
        return std::sqrt(s * (s - _a) * (s - _b) * (s - _c));
    }


private:
    double _a, _b, _c;
};
#if 0
class Factory
{
public:
    static Figure * createFigure(string name)
    {
        if(name == "circle")
        {
            return new Circle(); 
        }
        else if(name == "tranigle")
        {
            return new Traingle();
        }
        else
        {
            return nullptr;
        }

    }
};
#endif
class Factory
{
public:
    virtual Figure * createFigure() = 0;
    virtual ~Factory(){}
};

class CirclecreateFactory
:public Factory
{
public:
    Figure * createFigure()override
    {
        return new Circle(); 
    }

};
class TrainglecreateFactory
:public Factory
{
public:
    Figure * createFigure() override
    {
        return new Traingle(); 
    }
};
int main(int argc, char *argv[])
{
    CirclecreateFactory cf;
    TrainglecreateFactory tf;
    Figure * f1 = cf.createFigure();
    Figure * f2 = tf.createFigure();
    f1->display();
    cout << f1->getArea() << endl;
    f2->display();
    cout << f2->getArea() << endl;

    return 0;
}

